package com.photoeditor.demo.ui.activity.effect;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;


import com.common.base.ComponentContext;
import com.common.base.log.RLog;
import com.common.base.utils.AppUtils;
import com.common.base.utils.DebugUtil;
import com.common.base.utils.DeviceUtils;
import com.common.base.utils.TimeConstant;
import com.common.base.utils.thread.ThreadPool;
import com.common.commercialize.ad.AdDisplay;
import com.common.commercialize.ad.AdManager;
import com.common.commercialize.reward.RewardAdManager;
import com.common.commercialize.sdk.CommercializeSDK;
import com.common.commercialize.utils.TaskRunnable;
import com.photoeditor.R;
import com.photoeditor.demo.ad.AdItemBean;
import com.photoeditor.demo.ad.AdKeyConstant;
import com.photoeditor.demo.ad.AdProvider;
import com.photoeditor.demo.app.TestUser;
import com.photoeditor.demo.app.XActivity;
import com.photoeditor.demo.db.DataManager;
import com.photoeditor.demo.imageloader.ImageLoader;
import com.photoeditor.demo.model.event.CheckFloatWindowPermissionEvent;
import com.photoeditor.demo.model.event.DownloadFinishEvent;
import com.photoeditor.demo.model.event.RefreshStickerEvent;
import com.photoeditor.demo.model.event.SubscribeSuccessEvent;
import com.photoeditor.demo.model.image.util.ImageHelper;
import com.photoeditor.demo.model.preference.SPDataManager;
import com.photoeditor.demo.model.store.download.DownloadUtils;
import com.photoeditor.demo.model.store.download.IDownloadListener;
import com.photoeditor.demo.model.store.listener.ApplyActivityListener;
import com.photoeditor.demo.model.store.module.BaseOnlineManager;
import com.photoeditor.demo.model.store.module.HomeOnlineManager;
import com.photoeditor.demo.model.store.module.LocalPluginUtil;
import com.photoeditor.demo.model.store.module.StoreOnlineBean;
import com.photoeditor.demo.model.store.module.StoreOnlineManager;
import com.photoeditor.demo.model.subscribe.manager.AppVipManager;
import com.photoeditor.demo.model.subscribe.manager.SVipController;
import com.photoeditor.demo.statistics.NotifyStoreUpdateStatisticUtil;
import com.photoeditor.demo.statistics.StatisticsConstant;
import com.photoeditor.demo.statistics.StatisticsUtils;
import com.photoeditor.demo.ui.activity.GalleryActivity;
import com.photoeditor.demo.ui.adapter.effect.SetupWizardViewPageAdapter;
import com.photoeditor.demo.ui.adapter.effect.StickerDetailAdapter;
import com.photoeditor.demo.ui.dialog.MainPagePopGifPopup;
import com.photoeditor.demo.ui.widget.ChangeableRectButton;
import com.photoeditor.demo.ui.widget.CircleFillProgressView;
import com.photoeditor.demo.ui.widget.RoundRectProgressView;
import com.photoeditor.demo.ui.widget.transition.TransitionOptions;
import com.photoeditor.demo.ui.widget.transition.TransitionUtil;
import com.photoeditor.demo.util.APKAssertImageLoader;
import com.photoeditor.demo.util.FontUtil;
import com.photoeditor.demo.util.PermissionUtil;
import com.photoeditor.demo.util.PluginVersionUtil;
import com.photoeditor.demo.util.store.StoreConstant;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.lang.ref.WeakReference;
import java.util.ArrayList;

import butterknife.Bind;

import static com.photoeditor.demo.model.event.RefreshStickerEvent.OPERATION_REFRESH_AND_APPLY;
import static com.photoeditor.demo.model.store.module.BaseOnlineManager.STORE_FUNC_TYPE_STICKER;
import static com.photoeditor.demo.model.store.module.BaseOnlineManager.STORE_FUNC_TYPE_UNKNOWN;
import static com.photoeditor.demo.model.subscribe.manager.SVipConstant.VIP_ENTRANCE_EDIT;
import static com.photoeditor.demo.ui.adapter.home.HomeAdapter.isIsShowVipView;
import static com.photoeditor.demo.util.store.StoreConstant.REQUEST_CODE_START_DETAIL;

public class StickerDetailActivity extends XActivity implements View.OnClickListener/*, RewardAdManager.RewardListener*/ {

    public static final String EXTRA_STORE_ONLINE_BEAN = "EXTRA_STORE_ONLINE_BEAN";

    private StoreOnlineBean mData;

    private TextView mStickerName;

    private ImageView mCloseButton;

    private ViewPager mImagePager;

    protected SetupWizardViewPageAdapter mPageAdapter;

    private GridView mGridView;

    private StickerDetailAdapter mAdapter;

    private ArrayList<View> mList;

    private RelativeLayout mDownloadBtn;
    private ViewGroup mDownloadAdLayout;
    private View mDownloadAdMask;
    private  RelativeLayout downloadText;
    private ChangeableRectButton mWatchADBtn;
    private RoundRectProgressView mProgressView;
    private TextView mBottomIcon;
    private ValueAnimator valueAnimator;
    private ScrollView mScrollView;
    private View mContentLayout;

    private ViewGroup mAdContentLayout;
    private View mLayoutAdView;

    private boolean mShowingStickerPreview = false;
    private boolean isFreeToUnlock=false;
    private AdProvider mAdProvider;
    private String adCacheKey;




    //商店入口
    private int mStoreEntrance;
    //内部启动还是外部启动
//    private int mActivityLaunchFrom;

    private IDownloadListener mDownloadListener;
//    private String mStickerPreviewAdCacheKey;
    private MainPagePopGifPopup mMainPagePopGif;

//    private RewardAdManager mRewardAdManager;
    private boolean mIsNeedShowDownloadAd = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_sticker_details);
        Intent intent = getIntent();
        dealIntent(intent);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        // 更新本地的intent，否则getIntent()返回的是最初的
        setIntent(intent);
//        Fragment fragment = getFragmentManager().findFragmentByTag(DownloadAdDialog.TAG_DOWNLOAD_DIALOG);
//        if (fragment instanceof DownloadDialogFragment) {
//            ((DownloadDialogFragment) fragment).dismiss();
//        }
        dealIntent(intent);
    }

    private void dealIntent(Intent intent) {
        StatisticsUtils.statisicsCustomFunction("detail_in", "where", "sticker");

        mStoreEntrance = intent.getIntExtra(StoreConstant.store.EXTRA_STORE_ENTRANCE, StoreConstant.store.storeEntrance.ENTRANCE_NO);
//        mActivityLaunchFrom = intent.getIntExtra(ViewDetailActivity.KEY_BEAN_FROM, ViewDetailActivity.FROM_LOCAL);
        mData = (StoreOnlineBean) intent.getSerializableExtra(EXTRA_STORE_ONLINE_BEAN);
        if (mData != null) {
            initView();
            initDownload();
        } else {
            finish();
        }
        if (mData != null) {
            startTranstition();
        }

        loadStickerPreviewAd();

        loadLayoutAd();

        initRewardedVideoAd();

        if (mIsNeedShowDownloadAd) {
            loadDownloadAd();
        }
    }

    private void initRewardAd() {
//        mRewardAdManager = new RewardAdManager(this);
//        mRewardAdManager.setRewardListener(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        EventBus.getDefault().register(this);
//        if (mRewardAdManager != null) mRewardAdManager.onResumed();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onSubscribeSuccessEvent(SubscribeSuccessEvent event) {
        isFreeToUnlock = false;
        mBottomIcon.setText(R.string.button_apply);
    }

    @Override
    protected void onPause() {
        super.onPause();
        EventBus.getDefault().unregister(this);
//        if (mRewardAdManager != null) mRewardAdManager.onPaused();
    }

    private void initRewardedVideoAd() {
        // 首先判断滤镜分类是否需要付费
//        if (mData == null || isApply(mData.getId()) || mData.isDownloadOnGP() || !RewardAdManager.isStoreBeanNeedReward(mData, BaseOnlineManager.STORE_FUNC_TYPE_STICKER)) {
//            return;
//        }
//        mIsNeedShowDownloadAd = false;
//
//        initRewardAd();
//        mRewardAdManager.initRewardVideoAd();
    }

    public static void startActivity(Activity from, StoreOnlineBean bean, int storeEntrance) {
        startActivity(from, bean, storeEntrance, null, -1);
    }

    public static void startActivityWithAnimation(Activity from, StoreOnlineBean bean, int storeEntrance, View view) {
        startActivityWithAnimation(from, bean, storeEntrance, view, null, -1);
    }

    public static void startActivity(Activity from, StoreOnlineBean bean, int storeEntrance, String bannerFromWhere, int bannerPosition) {
        if (from == null || checkToJumpToApk(from, bean)) {
            return;
        }
        Intent intent = new Intent(from, StickerDetailActivity.class);
        intent.putExtra(StickerDetailActivity.EXTRA_STORE_ONLINE_BEAN, bean);
        intent.putExtra(StoreConstant.store.EXTRA_STORE_ENTRANCE, storeEntrance);
        intent.putExtra("bannerFromWhere", bannerFromWhere);
        intent.putExtra("bannerPosition", bannerPosition);
        from.startActivityForResult(intent, REQUEST_CODE_START_DETAIL);
        from.overridePendingTransition(R.anim.activity_open_enter, R.anim.activity_no_animation);
    }

    public static void startActivityWithAnimation(Activity from, StoreOnlineBean bean, int storeEntrance, View view, String bannerFromWhere, int bannerPosition) {
        if (from == null || checkToJumpToApk(from, bean)) {
            return;
        }
        TransitionOptions options = TransitionOptions.makeTransitionOptions(from, view);
        Intent intent = new Intent(from, StickerDetailActivity.class);
        intent.putExtra(StickerDetailActivity.EXTRA_STORE_ONLINE_BEAN, bean);
        intent.putExtra(StoreConstant.store.EXTRA_STORE_ENTRANCE, storeEntrance);
        intent.putExtra("bannerFromWhere", bannerFromWhere);
        intent.putExtra("bannerPosition", bannerPosition);
        TransitionUtil.startActivityForResult(intent, REQUEST_CODE_START_DETAIL, options);
    }

    private static boolean checkToJumpToApk(Activity activity, StoreOnlineBean storeOnlineBean) {
        if (storeOnlineBean == null
                || !storeOnlineBean.isDownloadOnGP()) {
            return false;
        }
//        if (PackageReceiver.isPackageInstall(storeOnlineBean.getPkgName())) {
//            Intent launchIntent = activity.getPackageManager().getLaunchIntentForPackage(storeOnlineBean.getPkgName());
//            if (launchIntent != null) {
//                activity.startActivity(launchIntent);
//                return true;
//            }
//        }
        return false;
    }

    private void startTranstition() {
        boolean start = TransitionUtil.enterDepandTargetSize(
                this,
                300,
                new DecelerateInterpolator(),
                new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        ThreadPool.runUITask(new Runnable() {
                            @Override
                            public void run() {
                                findViewById(R.id.store_icon).setVisibility(View.GONE);
                            }
                        }, 500);
                        mImagePager.setAlpha(1);
                        animation.removeListener(this);
                    }

                    @Override
                    public void onAnimationStart(Animator animation) {
                        super.onAnimationStart(animation);
                        onTranstitionAniStart();
                        mScrollView.setAlpha(0);
                    }
                });
        if (start) {
            onPreTranstition();
        }
    }

    private void onTranstitionAniStart() {
        ThreadPool.runUITask(new Runnable() {
            @Override
            public void run() {
                mImagePager.setAlpha(0);
                View title = findViewById(R.id.detail_layout);
                startTranslateYAnimation(title, DeviceUtils.dip2px(getApplicationContext(), 75), 360);
            }
        }, 200);
        ThreadPool.runUITask(new Runnable() {
            @Override
            public void run() {
                mScrollView.animate().alpha(1).setDuration(360).start();
                View tip = findViewById(R.id.tip_layout);
                int y = DeviceUtils.dip2px(getApplicationContext(), 77);
                startTranslateYAnimation(tip, y, 360);
                startTranslateYAnimation(mGridView, y, 360);
            }
        }, 320);
        mContentLayout.setBackgroundColor(Color.TRANSPARENT);
        ValueAnimator animator = ValueAnimator.ofInt(0, 255);
        animator.setDuration(360);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                mContentLayout.setBackgroundColor(Color.argb((Integer) animation.getAnimatedValue(), 255, 255, 255));
            }
        });
        animator.start();
    }

    private void onPreTranstition() {
        ImageView imageView = (ImageView) findViewById(R.id.store_icon);
        imageView.setVisibility(View.VISIBLE);
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
        layoutParams.height = mImagePager.getLayoutParams().height;
        layoutParams.width = mImagePager.getLayoutParams().width;
        imageView.setLayoutParams(layoutParams);
        if (mData != null && mData.getPreview() != null) {
            String[] urls = mData.getPreview().split("#");
//            if (mActivityLaunchFrom == ViewDetailActivity.FROM_OUTER) {
//                try {
//                    Context packageContext = ComponentContext.getContext().createPackageContext(mData.getPkgName(), Context.CONTEXT_IGNORE_SECURITY);
//                    String rootUrl = StoreOnlineBean.removeQueryString(mData.getRootUrl());
//                    String assertPath = StoreOnlineBean.removeQueryString(urls[0]).substring(rootUrl == null ? 0 : rootUrl.length() + 1);
//                    APKAssertImageLoader.with(packageContext.getResources()).load(assertPath).into(imageView);
//                } catch (PackageManager.NameNotFoundException e) {
//                    e.printStackTrace();
//                    ImageLoader.loadImage(this, urls[0], R.drawable.default_image, imageView);
//                }
//
//            } else {
                ImageLoader.loadImage(this, urls[0], R.drawable.ic_default_image, imageView);
//            }
        }
    }

    private void startTranslateYAnimation(View view, int translateY, int during) {
        ObjectAnimator animator = ObjectAnimator.ofFloat(view, "translationY", translateY, 0);
        animator.setDuration(during);
        animator.start();
    }

    private void initDownload() {
        String pkgName = mData.getPkgName();
        if (!TextUtils.isEmpty(pkgName)) {
            mDownloadListener = new DownloadListener(pkgName, this);
            DownloadUtils.getInstance().addListener(mDownloadListener);
            boolean isApply = isApply(pkgName);
            //初始化下载按钮
            if (isApply) {
                updateUIOfInstall();
            } else if (isDownloading()) {
                mDownloadBtn.setVisibility(View.GONE);
                int percent = DownloadUtils.getInstance().getPercentage(pkgName);
                mProgressView.setProgress(percent == 0 ? 1 : percent);
                mProgressView.setVisibility(View.VISIBLE);
                downloadText.setVisibility(View.VISIBLE);
                mWatchADBtn.setVisibility(View.GONE);
//                if(mData.isBuy()){
//                    mWatchADBtn.setVisibility(View.VISIBLE);
//                    mWatchADBtn.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
//                        @Override
//                        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
//                            mWatchADBtn.setOffset();
//                            mWatchADBtn.removeOnLayoutChangeListener(this);
//                        }
//                    });
//                }
            } else {
//                if (!mData.isDownloadOnGP() && !RewardAdManager.isStoreBeanNeedReward(mData, BaseOnlineManager.STORE_FUNC_TYPE_STICKER)) {
//                    loadDownloadAd();
//                }
                updateUIOfUninstall();
            }
        }
    }

    private void onReward() {
        mIsNeedShowDownloadAd = false;
        if (mData.isDownloadOnGP()) {
//            ProductDrive.gotoGPStoreOrBrowser(ComponentContext.getContext(), Global.GP_URL_WITH_UTM.replace(Global.PACKAGE_NAME_REPLACEMENT, mData.getPkgName()));
            statisticsDownload();
            mWatchADBtn.setGPType();
            mWatchADBtn.setVisibility(View.VISIBLE);
            mDownloadBtn.setVisibility(View.GONE);
            mProgressView.setVisibility(View.GONE);
        } else {
            mWatchADBtn.setEnabled(false);
            mWatchADBtn.startAnim(new ChangeableRectButton.ChangeBtnListener() {
                @Override
                public void onAnimEnd() {
                    mWatchADBtn.setVisibility(View.GONE);
                    startDownload(true);
                }
            });
        }
        postDelayed(new Runnable() {
            @Override
            public void run() {
                EventBus.getDefault().post(new RefreshStickerEvent(RefreshStickerEvent.OPERATION_REFRESH, mData.getPkgName()));
            }
        }, 500);
    }


    private void initView() {
        downloadText=(RelativeLayout) findViewById(R.id.download_text);
        mDownloadBtn = (RelativeLayout) findViewById(R.id.iv_category_download);
        mDownloadAdLayout=(ViewGroup)findViewById(R.id.ad_view);
        mDownloadAdMask=(View)findViewById(R.id.ad_mask);
        mDownloadBtn.setOnClickListener(this);
        mProgressView = (RoundRectProgressView) findViewById(R.id.progress_view);
        mBottomIcon = (TextView) findViewById(R.id.iv_download);
        mContentLayout = findViewById(R.id.content_layout);
        mScrollView = (ScrollView) findViewById(R.id.scrollview);
        mCloseButton = (ImageView) findViewById(R.id.sticker_details_close);
        mImagePager = (ViewPager) findViewById(R.id.sticker_details_pager);
        mWatchADBtn = (ChangeableRectButton) findViewById(R.id.btn_watch_ad);
        mAdContentLayout = (ViewGroup) findViewById(R.id.ad_content_layout);
        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mImagePager.getLayoutParams();
        lp.height = ImageHelper.SCREEN_WIDTH * 2 / 3;
        lp.width = ImageHelper.SCREEN_WIDTH;
        mImagePager.setLayoutParams(lp);

        mGridView = (GridView) findViewById(R.id.gridview);
        mStickerName = (TextView) findViewById(R.id.sticker_name);
        FontUtil.setCustomFont(mStickerName, (TextView) findViewById(R.id.text_message));
        String nameStr = mData.getName().replaceAll("[A-Z]", " $0");//正则替换注意“ $0”前面有个空格
        mStickerName.setText(nameStr);
        mCloseButton.setOnClickListener(this);
        mWatchADBtn.setOnClickListener(this);
        if (!TextUtils.isEmpty(mData.getPreview())) {
            String[] urls = mData.getPreview().split("#");
            int size = urls.length;

            mList = new ArrayList<>(size);
            Resources packageResources = null;
//            if (mActivityLaunchFrom == ViewDetailActivity.FROM_OUTER) {
//                try {
//                    packageResources = ComponentContext.getContext().createPackageContext(mData.getPkgName(), Context.CONTEXT_IGNORE_SECURITY).getResources();
//                } catch (PackageManager.NameNotFoundException e) {
//                    e.printStackTrace();
//                }
//            }
            String rootUrl = StoreOnlineBean.removeQueryString(mData.getRootUrl());
            for (int i = 0; i < size; i++) {
                ImageView imageView = new ImageView(this);
                imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                imageView.setImageResource(R.drawable.ic_default_image);
                if (packageResources != null) {
                    String assertPath = StoreOnlineBean.removeQueryString(urls[i]).substring(rootUrl == null ? 0 : rootUrl.length() + 1);
                    APKAssertImageLoader.with(packageResources).load(assertPath).into(imageView);
                } else {
                    ImageLoader.loadImage(this, urls[i], R.drawable.ic_default_image, imageView);
                }
                mList.add(imageView);
            }
            mPageAdapter = new SetupWizardViewPageAdapter(mList);
            mImagePager.setAdapter(mPageAdapter);
        } else {
            if (mList != null) {
                mList.clear();
                mPageAdapter = new SetupWizardViewPageAdapter(mList);
                mImagePager.setAdapter(mPageAdapter);
            }
        }

        if (mMainPagePopGif != null && mMainPagePopGif.isShowing()) {
            mMainPagePopGif.dismiss();
        }

        if (mData.getStickerUrls() != null) {
            int width = (ImageHelper.SCREEN_WIDTH - 5 * getResources().getDimensionPixelSize(R.dimen.store_sticker_detail_padding)) / 4;
            mAdapter = new StickerDetailAdapter(this, mData, width, width, false);
            mGridView.setAdapter(mAdapter);
            mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    showPreviewWindow(position);
                }
            });
        }
        mGridView.post(new Runnable() {
            @Override
            public void run() {
                mScrollView.scrollTo(0, 0);//由于刚刚开始无法确定GridView的高度  会导致ScrollView显示不正常
            }
        });

        showLayoutAd();

        mProgressView.setMaxCount(100);


//        StatisticsUtils.statisticsCustomStoreShow(
//                StatisticsConstant.UMENG_CUSTOM_EVENT_FUNC_STORE_VALUE_STICKER_PAGE_SHOW + "_" + mData.getName());
    }

    private void showLayoutAd() {

    }

    private void showPreviewWindow(int position) {
        if (this.isDestroyed()) {
            return;
        }
        if (!mShowingStickerPreview) {
            mShowingStickerPreview = true;
            mMainPagePopGif = new MainPagePopGifPopup(StickerDetailActivity.this, mData.getStickerUrls(), position, false, mData.getPkgName(), mData.getRootUrl());
            mMainPagePopGif.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    mShowingStickerPreview = false;
                    mMainPagePopGif = null;
                }
            });
            mMainPagePopGif.setOnApplyBtnClickListener(new MainPagePopGifPopup.OnApplyBtnClickListener() {
                @Override
                public void onApplyBtnClick(int position) {
                    onPreviewBtnClicked(position);
                }
            });
            if (isApply(mData.getPkgName())) {
                if(CommercializeSDK.getInstance().isBuyUser()) {
                    mMainPagePopGif.setApplyBtnVisibility(View.GONE);
                } else {
                    mMainPagePopGif.setApplyBtnVisibility(View.VISIBLE);
                }
            } else {
                if(CommercializeSDK.getInstance().isBuyUser()) {
                    mMainPagePopGif.setApplyBtnVisibility(View.GONE);
                } else {
                    mMainPagePopGif.setApplyBtnVisibility(View.VISIBLE);
                    updatePreviewProgress(-1);
                }
            }
            mMainPagePopGif.showMainPagePopGif(mContentLayout, Gravity.CENTER, 0, 0);
        }
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.sticker_details_close) {
            onExist();
        } else if (i == R.id.iv_category_download) {
            onDownloadBtnClicked(-1);
        } else if (i == R.id.btn_watch_ad) {
            // 外部包与广告按钮延时一样id
//            if (mWatchADBtn.getType() == ChangeableRectButton.TYPE_GP && mData.isDownloadOnGP()) {
//                ProductDrive.gotoGPStoreOrBrowser(ComponentContext.getContext(), Global.GP_URL_WITH_UTM.replace(Global.PACKAGE_NAME_REPLACEMENT, mData.getPkgName()));
//                statisticsDownload();
//            } else if (mWatchADBtn.getType() == ChangeableRectButton.TYPE_VIDEO_AD) {
//                if (mRewardAdManager == null) {
//                    if (DebugUtil.isDebuggable() || CommercializeSDK.TestUser.isTestUser()) {
//                        throw new RuntimeException("reward ad manager is null");
//                    }
//                } else {
//                    mRewardAdManager.showHintDialog(mData, BaseOnlineManager.STORE_FUNC_TYPE_STICKER, v);
//                }
//                StatisticsUtils.statisticsCustomStoreClick(StatisticsConstant.UMENG_CUSTOM_EVENT_FUNC_STORE_VALUE_STICKER_CATEGORY_SHOW
//                        + "_" + mData.getName());
//            }
        }
    }

    private void onPreviewBtnClicked(int position) {
        boolean isApply = isApply(mData.getPkgName());
        if (isApply) {
            dealApply(mData.getPkgName(), position);
            mMainPagePopGif.dismiss();
        } else if (isDownloading()) {
        }  else {
//            if (!RewardAdManager.isStoreBeanNeedReward(mData, STORE_FUNC_TYPE_STICKER) || mData.isDownloadOnGP()) {
//                if(mData.isDownloadOnGP()) {
//                    mMainPagePopGif.dismiss();
//                    if (PackageReceiver.isPackageInstall(mData.getPkgName())) {
//                        Intent launchIntent = getPackageManager().getLaunchIntentForPackage(mData.getPkgName());
//                        if (launchIntent != null) {
//                            startActivity(launchIntent);
//                        }
//                    } else {
//                        ProductDrive.gotoGPStoreOrBrowser(ComponentContext.getContext(), Global.GP_URL_WITH_UTM.replace(Global.PACKAGE_NAME_REPLACEMENT, mData.getPkgName()));
//                        statisticsDownload();
//                    }
//                } else {
                    // 启动下载
                    DownloadUtils.getInstance().startDownload(mData, STORE_FUNC_TYPE_STICKER);
                    loadAnimStart();
                    updatePreviewProgress(1);
//                    RateGuide.showRate(this);
                    statisticsDownload();
//                }
//            } else {
//                if (mRewardAdManager == null) {
//                    if (DebugUtil.isDebuggable() || CommercializeSDK.TestUser.isTestUser()) {
//                        throw new RuntimeException("reward ad manager is null");
//                    }
//                } else {
//                    mRewardAdManager.showHintDialog(mData, STORE_FUNC_TYPE_STICKER, mDownloadBtn);
//                    mMainPagePopGif.dismiss();
//                }
//                StatisticsUtils.statisticsCustomStoreClick(StatisticsConstant.UMENG_CUSTOM_EVENT_FUNC_STORE_VALUE_STICKER_CATEGORY_SHOW
//                        + "_" + mData.getName());
//            }
        }
    }

    private void onDownloadBtnClicked(int position) {
        if (!TextUtils.isEmpty(mData.getPkgName())) {
            boolean isApply = isApply(mData.getPkgName());
            if (isApply) {
                if(isFreeToUnlock) {//是订阅
                    SVipController.showFunctionSubscribe(this, VIP_ENTRANCE_EDIT, StatisticsConstant.ENTRANCE_VALUE_STICKER, null);
                    return;
                }
                dealApply(mData.getPkgName(), position);
            } else if (isDownloading()) {
                // TODO:正在下载，接口不支持暂停，先不处理
            } else {
                StatisticsUtils.statisicsCustom(StatisticsConstant.UMENG_CUSTOM_EVENT_PREFIX_FUNCTION, "download_state",
                        "event", "free_click");
//                if (mData.isDownloadOnGP()) {
//                    if (PackageReceiver.isPackageInstall(mData.getPkgName())) {
//                        Intent launchIntent = getPackageManager().getLaunchIntentForPackage(mData.getPkgName());
//                        if (launchIntent != null) {
//                            startActivity(launchIntent);
//                        }
//                        statisticsApply();
//                    } else {
//                        ProductDrive.gotoGPStoreOrBrowser(ComponentContext.getContext(), Global.GP_URL_WITH_UTM.replace(Global.PACKAGE_NAME_REPLACEMENT, mData.getPkgName()));
//                        statisticsDownload();
//                    }
//                } else {
                    // 启动下载
                    startDownload(false);
//                    RateGuide.showRate(this);
//                }
            }
        }
    }

    private void statisticsDownload() {
        SPDataManager.setDownloadCountToday(SPDataManager.getDownloadCountToday() + 1);
        SPDataManager.addDownloadCountOfDay();

        //统计banner下载
        String bannerFromWhere = getIntent().getStringExtra("bannerFromWhere");
        int position = getIntent().getIntExtra("bannerPosition", -1);
        if(!TextUtils.isEmpty(bannerFromWhere) && position != -1) {
            StatisticsUtils.statisticsBannerDownload(bannerFromWhere, position);
            StatisticsUtils.statisticsAllBannerDownload();
        }

        //通知栏更新
        NotifyStoreUpdateStatisticUtil.statisticDownload(mData.getPkgName());
    }

    private void startDownload(boolean isBuy) {
        if (mIsNeedShowDownloadAd) {
            loadDownloadAd();
        }
        DownloadUtils.getInstance().startDownload(mData, STORE_FUNC_TYPE_STICKER);
        if (!isBuy) {
            mProgressView.setProgress(1);
            mProgressView.setVisibility(View.VISIBLE);
            downloadText.setVisibility(View.VISIBLE);

            //loadAnimStart();
        } else {
            if (mProgressView != null) {
                mProgressView.setProgress(1);
                mProgressView.setVisibility(View.VISIBLE);
                downloadText.setVisibility(View.VISIBLE);

            }
        }
        showDownloadDialog(mData);

//        ApplyAdProvider.getInstance().loadAd();

        statisticsDownload();
    }

    private void showApplyAd(boolean disBuyuser, TaskRunnable taskRunnable) {
//        ApplyAdProvider.getInstance().loadAndShowAd(disBuyuser, taskRunnable);
        taskRunnable.runSelfAdaptation();
    }

    private void loadAnimStart() {
        valueAnimator = ValueAnimator.ofFloat(1f, 0f);
        valueAnimator.setDuration(400);
        valueAnimator.start();
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float value = (float) animation.getAnimatedValue();
                if (mDownloadBtn != null) {
                    mDownloadBtn.setAlpha(value);
                    mDownloadBtn.setScaleX(value);
                    mDownloadBtn.setScaleY(value);
                }
            }
        });
        valueAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (mProgressView != null && !LocalPluginUtil.isInsidePkg(mData.getPkgName())) {
                    mProgressView.setProgress(1);
                    mProgressView.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    private boolean isDownloading() {
        boolean isDownloading = false;
        switch (DownloadUtils.getInstance().getDownloadStatus(mData.getPkgName())) {
            case DownloadUtils.DOWNLOAD_DEFAULT:
            case DownloadUtils.DOWNLOAD_END:
                isDownloading = false;
                break;
            case DownloadUtils.DOWNLOAD_CLICK:
            case DownloadUtils.DOWNLOAD_BING:
                isDownloading = true;
                break;

        }
        return isDownloading;
    }

    private boolean isApply(String packageName) {
        boolean ret = false;
        if (!TextUtils.isEmpty(packageName)) {
            ret = DataManager.getInstance().isExistSticker(packageName);
        }
        return ret;
    }

    private boolean isInstallApk(String packageName) {
        return false;//PackageReceiver.isPackageInstall(packageName);
    }

    private void dealApply(final String pkgName, final int position) {
        if (mData != null && !PluginVersionUtil.verifyPluginVersion(this,
                STORE_FUNC_TYPE_STICKER,
                mData.getVersioncode())) {
            return;
        }
        showApplyAd(true, new TaskRunnable(TaskRunnable.TYPE_MAIN) {
            @Override
            public void run() {
                Class<?> classType = ApplyActivityListener.getInstance().getApplyClass(STORE_FUNC_TYPE_STICKER);
                if (classType == null) {
                    GalleryActivity.startGallerySelectImageToAutoAddSticker(StickerDetailActivity.this, pkgName, "", position);
                } else {
//            setResult(RESULT_CODE_APPLIED);
//            finish();
                    EventBus.getDefault().post(new RefreshStickerEvent(OPERATION_REFRESH_AND_APPLY, pkgName, position));
                    Intent intent = new Intent(StickerDetailActivity.this, classType);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                }
                statisticsApply();
            }
        });

    }

    private void statisticsApply() {

        //统计banner应用
        String bannerFromWhere = getIntent().getStringExtra("bannerFromWhere");
        int position = getIntent().getIntExtra("bannerPosition", -1);
        if(!TextUtils.isEmpty(bannerFromWhere) && position != -1) {
            StatisticsUtils.statisticsBannerApply(bannerFromWhere, position);
            StatisticsUtils.statisticsAllBannerApply();
        }

        //通知栏更新
        NotifyStoreUpdateStatisticUtil.statisticApply(mData.getPkgName());
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        if (mRewardAdManager != null) mRewardAdManager.onDestroy();
        if (mAdapter != null) {
            mAdapter.destory();
        }
        if (mDownloadListener != null) {
            DownloadUtils.getInstance().removeListener(mDownloadListener);
        }
        if (mMainPagePopGif != null && mMainPagePopGif.isShowing()) {
            mMainPagePopGif.dismiss();
            mMainPagePopGif = null;
        }
        destoryStickerPreviewAd();
        destroyLayoutPreviewAd();

        if (mAdProvider != null) {
            mAdProvider.destroy();
        }
    }

    private void endDownload(boolean success) {
        loadAnimEnd(success);
    }

    private void loadAnimEnd(boolean success) {
        mProgressView.setProgress(0);
        mProgressView.setVisibility(View.GONE);
        downloadText.setVisibility(View.GONE);
        mWatchADBtn.setVisibility(View.GONE);
        mWatchADBtn.setEnabled(true);
        mDownloadBtn.setVisibility(View.VISIBLE);
        if (success) {
            if(isIsShowVipView()){
                if( mData.isBuy() && AppVipManager.isVip()){
                    isFreeToUnlock=false;
                    mBottomIcon.setText(R.string.button_apply);
                }else{
                    isFreeToUnlock=true;
                    mBottomIcon.setText(R.string.button_free_to_unlock);
                    StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MP_BUTT_SHOW);
                }
            }else{
                isFreeToUnlock=false;
                mBottomIcon.setText(R.string.button_apply);
            }
        } else {
            mBottomIcon.setText(R.string.emoji_download1);
        }
        valueAnimator = ValueAnimator.ofFloat(0f, 1f);
        valueAnimator.setDuration(400);
        valueAnimator.start();
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float value = (float) animation.getAnimatedValue();
                if (mDownloadBtn != null) {
                    mDownloadBtn.setAlpha(value);
                    mDownloadBtn.setScaleX(value);
                    mDownloadBtn.setScaleY(value);
                }
            }
        });
    }

    private void updateProgress(int progress) {
        if (progress == 0) {
            progress = 1;
        }
        mProgressView.setProgress(progress);
        //updatePreviewProgress(progress);
        if (progress == 100) {
            post(new Runnable() {
                @Override
                public void run() {
                    endDownload(true);
                    //updatePreviewProgress(100);
                }
            });
        }
    }

    private void onDwonloadFailed() {
        postDelayed(new Runnable() {
            @Override
            public void run() {
                if (isFinishing()) {
                    return;
                }
                Toast.makeText(StickerDetailActivity.this, getResources().getString(R.string.filter_download_failed), Toast.LENGTH_SHORT).show();
                mDownloadBtn.setAlpha(1);
                mDownloadBtn.setScaleX(1);
                mDownloadBtn.setScaleY(1);
                mBottomIcon.setText(R.string.emoji_download1);
                mProgressView.setVisibility(View.GONE);
                downloadText.setVisibility(View.GONE);
                mDownloadBtn.setVisibility(View.VISIBLE);
                updatePreviewProgress(-1);
            }
        }, TimeConstant.ONE_SEC);
    }

//    @Override
//    public void onReward(StoreOnlineBean bean) {
//        onReward();
//    }

    public static class DownloadListener implements IDownloadListener {
        private String mDownloadId;
        private WeakReference<StickerDetailActivity> mActivityRef;
        private String mFullActivityName;

        public DownloadListener(String pkgName, StickerDetailActivity activity) {
            mDownloadId = pkgName;
            mActivityRef = new WeakReference<>(activity);
            mFullActivityName = activity.getClass().getCanonicalName();
        }

        @Override
        public String getDownloadId() {
            return mDownloadId;
        }

        @Override
        public void onProgressUpdate(String downloadId, final int progress) {
            if (!TextUtils.isEmpty(downloadId) && mDownloadId.equals(downloadId)) {
                if (mActivityRef != null && mActivityRef.get() != null && !mActivityRef.get().isFinishing()) {
                    mActivityRef.get().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mActivityRef.get().updateProgress(progress);
                        }
                    });
                }
            }
        }

        @Override
        public void onFailed(String downloadId) {
            if (!TextUtils.isEmpty(downloadId) && mDownloadId.equals(downloadId)) {
                if (mActivityRef != null && mActivityRef.get() != null && !mActivityRef.get().isFinishing()) {
                    mActivityRef.get().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mActivityRef.get().onDwonloadFailed();
                        }
                    });
                }
            }
        }

        @Override
        public String getFullActivityName() {
            return mFullActivityName;
        }
    }

    private void loadDownloadAd() {

        String unitId = AdKeyConstant.InappAdPlacementID.DOWNLOAD_ID;
        final int adTouchType = AdDisplay.AdTouchType.DEFAULT;
        String sceneName = "vipdownload";
        if(mAdProvider == null) {
            mAdProvider = AdProvider.newProvider(sceneName, unitId, -1);
            mAdProvider.addStatisticsInfo(StatisticsConstant.KEY_MAIN_PAGE_FUN, StatisticsConstant.ENTRANCE_VALUE_STICKER);
            mAdProvider.setOnAdListener(new AdProvider.OnAdListener() {
                @Override
                public void onAdLoadFinish(String cacheKey) {
                    if (mAdProvider == null) {
                        AdProvider.statisticsNoShowAd(sceneName, AdProvider.REASON_PAGE_NO_SHOWING);
                    }

                    if (mDownloadAdLayout != null) {
                        if (!TextUtils.isEmpty(adCacheKey)) {
                            AdManager.getInstance().destoryAd(adCacheKey);
                        }
                        boolean isAdValid = true;
                        if (!mAdProvider.hasAd()) {
                            isAdValid = false;
                        }

                        if (!isAdValid) {
                            mAdProvider.statisticsNoShowAd(AdProvider.REASON_NO_VALID_AD);
                            return;
                        } else {
                            adCacheKey = mAdProvider.getAdCacheKey();
                        }
                    } else {
                        AdProvider.statisticsNoShowAd(sceneName, AdProvider.REASON_PAGE_NO_SHOWING);
                    }
                }

                @Override
                public void onAdLoadFailure(String err) {

                }

                @Override
                public void onAdClicked(String cacheKey) {
//                    if(mBottomDatas == null || mBottomRecyclerAdapter == null) {
//                        return;
//                    }
//                    if (index >= 0 && index < mBottomDatas.size()) {
//                        mBottomDatas.remove(index);
//                        mBottomRecyclerAdapter.notifyDataSetChanged();
//                        return;
//                    }
//                    IItemBean needDelBean = null;
//                    for (IItemBean bean : mBottomDatas) {
//                        if (bean instanceof AdItemBean) {
//                            if (TextUtils.equals(cacheKey, ((AdItemBean) bean).getAdCacheKey())) {
//                                needDelBean = bean;
//                                break;
//                            }
//                        }
//                    }
//                    if (needDelBean != null) {
//                        mBottomDatas.remove(needDelBean);
//                        mBottomRecyclerAdapter.notifyDataSetChanged();
//                    }
                }

                @Override
                public void onAdImpression(String cacheKey) {

                }
            });
        }
        if (mAdProvider.hasAd()) {
            mAdProvider.loadAd();
        }

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onDownloadFinish(DownloadFinishEvent event) {
        StoreOnlineBean downloadBean = event.getDownloadBean();
//        showDownloadDialog(downloadBean);
    }

    private void showDownloadDialog(final StoreOnlineBean downloadBean) {
        if (downloadBean == null) {
            if (DebugUtil.isDebuggable() || TestUser.isTestUser()) {
                RLog.v(this.getClass().getSimpleName(), "store_download, " + downloadBean.getName() + " bean not equals");
            }
            return;
        }
        if (!mIsNeedShowDownloadAd) {
            if (DebugUtil.isDebuggable() || TestUser.isTestUser()) {
                RLog.v(this.getClass().getSimpleName(), "store_download, " + downloadBean.getName() + " bean is not need ad");
            }
            return;
        }

        if (TextUtils.isEmpty(adCacheKey) || !mAdProvider.hasAd()) {
            return;
        }
        AdItemBean adItemBean = new AdItemBean(adCacheKey);
        adItemBean.setNeedLimitAdHeight(true);
        adItemBean.setAdTouchType(AdDisplay.AdTouchType.DEFAULT);

        View adView = adItemBean.createAdView(R.layout.ad_filter_download_view);

        ViewGroup downloadAdLayout = mDownloadAdLayout.findViewById(R.id.download_ad_layout);
        downloadAdLayout.removeAllViews();
        downloadAdLayout.addView(adView);
        mDownloadAdLayout.setVisibility(View.VISIBLE);
        mDownloadAdMask.setVisibility(View.VISIBLE);
        mDownloadAdLayout.findViewById(R.id.ic_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDownloadAdLayout.setVisibility(View.GONE);
                mDownloadAdMask.setVisibility(View.GONE);
            }
        });
        mDownloadAdMask.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //拦截点击，不做处理
            }
        });
    }

    private void loadStickerPreviewAd() {

    }

    private void destoryStickerPreviewAd() {

    }

    private void loadLayoutAd() {

    }

    private void destroyLayoutPreviewAd() {

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void refreshSticker(final RefreshStickerEvent event) {
        if (mData != null && mData.getPkgName().equals(event.stickerPkgName)) {
            if (event.operation == RefreshStickerEvent.OPERATION_REFRESH_AND_DELETE) {
                updateUIOfUninstall();
                updatePreviewProgress(-1);
            } else if (event.operation == RefreshStickerEvent.OPERATION_REFRESH) {
                if (isApply(mData.getPkgName())) {
                    updateUIOfInstall();
                    updatePreviewProgress(100);
                }
            }
        }
    }

    private void updateUIOfInstall() {
        if(isIsShowVipView()){
            if(mData.isBuy() && AppVipManager.isVip()){
                isFreeToUnlock=false;
                mBottomIcon.setText(R.string.button_apply);
            }else{
                isFreeToUnlock=true;
                mBottomIcon.setText(R.string.button_free_to_unlock);
                StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_MP_BUTT_SHOW);
            }
        }else{
            isFreeToUnlock=false;
            mBottomIcon.setText(R.string.button_apply);
        }
        mDownloadBtn.setVisibility(View.VISIBLE);
        mProgressView.setVisibility(View.GONE);
        downloadText.setVisibility(View.GONE);
        mWatchADBtn.setVisibility(View.GONE);
    }

    private void updateUIOfUninstall() {
        /*if (mData.isDownloadOnGP()){
            if (PackageReceiver.isPackageInstall(mData.getPkgName())) {
                mBottomIcon.setImageResource(R.drawable.store_icon_apply);
                mDownloadBtn.setVisibility(View.VISIBLE);
                mProgressView.setVisibility(View.GONE);
                mWatchADBtn.setVisibility(View.GONE);
            } else {
                mWatchADBtn.setGPType();
                mWatchADBtn.setVisibility(View.VISIBLE);
                mDownloadBtn.setVisibility(View.GONE);
                mProgressView.setVisibility(View.GONE);
            }
        } else */{
//            if (RewardAdManager.isStoreBeanNeedReward(mData, STORE_FUNC_TYPE_STICKER)) {
//                mWatchADBtn.setVideoADType(mData.isDownloadOnGP());
//                mWatchADBtn.setVisibility(View.VISIBLE);
//                mDownloadBtn.setVisibility(View.GONE);
//                mProgressView.setVisibility(View.GONE);
//            } else {
                mBottomIcon.setText(R.string.emoji_download1);
                mDownloadBtn.setVisibility(View.VISIBLE);
                mProgressView.setVisibility(View.GONE);
                downloadText.setVisibility(View.GONE);
                mWatchADBtn.setVisibility(View.GONE);
//            }
        }
    }

    private boolean canLoadAssertBitmap() {
        if (mData != null && mData.isDownloadOnGP() && isApply(mData.getPkgName()) && AppUtils.isInstalledAppByPkgName(ComponentContext.getContext(), mData.getPkgName())) {
            return true;
        }
        return false;
    }

    public void updatePreviewProgress(int percentage) {
        if(mMainPagePopGif != null && mShowingStickerPreview) {
            Resources res = getResources();
            String percentageStr = "";
            if (percentage < 0) {
                // 未下载状态
                mMainPagePopGif.setProgress(0);
                int beanType = HomeOnlineManager.getInstance().getBeanType(mData);
                if (beanType == STORE_FUNC_TYPE_UNKNOWN) {
                    beanType = StoreOnlineManager.getInstance().getBeanType(mData);
                }
                /*if (!RewardAdManager.isStoreBeanBuy(mData, beanType)) {
                    percentageStr = res.getString(R.string.high_rating_dialog_free);
                }*/ /*else if (SVipManager.getInstance().isSVipUser() || BillingManager.getInstance().isPurchased(Sku.getResSku(mData.getPkgName(), beanType))) {
                    percentageStr = res.getString(R.string.store_get_free);
                } */else {
                    percentageStr = res.getString(R.string.store_get);
                }
//                if (mData.isDownloadOnGP()) {
//                    mMainPagePopGif.setDownText(percentageStr, R.drawable.goods_download_btn, res.getColor(R.color.accent_color), R.drawable.ic_gp_homepage);
//                } else {
                    mMainPagePopGif.setDownText(percentageStr, R.drawable.goods_download_btn, res.getColor(R.color.accent_color));
//                }
            } else if (percentage == 0) {
                // 开始下载初始化
                mMainPagePopGif.setProgress(percentage);
                percentageStr = percentage + "%";
                mMainPagePopGif.setDownText(percentageStr, R.drawable.goods_download_btn, res.getColor(R.color.primary_color));
            } else if (percentage >= 0 && percentage < 100) {
                // 下载中
                percentageStr = percentage + "%";
                mMainPagePopGif.setProgress(percentage);
                mMainPagePopGif.setDownText(percentageStr, R.drawable.goods_download_btn, res.getColor(R.color.primary_color));
            } else if (percentage >= 100) {
                // 下载完成
                mMainPagePopGif.setProgress(100);
                mMainPagePopGif.setDownText(R.string.store_apply, R.drawable.goods_download_progress_selector, Color.WHITE);
            }
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        if(!mShowingStickerPreview) {
            onExist();
        }
    }

    public void onExist() {
        //通知栏更新
        NotifyStoreUpdateStatisticUtil.clear();
        finish();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == PermissionUtil.PERMISSION_REQ_CODE) {
            EventBus.getDefault().post(new CheckFloatWindowPermissionEvent());
        }
    }

}
